﻿
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using GruntXProductions;
using Viper;
using Viper.Opcodes;

namespace Diamond
{
    public partial class CodeGen
    {
        public void CreateOperator(OperatorOverload method)
        {
            if (method.Arguments.Count != 2)
                Errors.Add("Operator overload can only have 2 arguments!");
            Symbols.BeginScope();
			this.ReturnType = method.Type;
            Assembler.CreateLabel(GetMethodName(method));
            method.Arguments.Reverse();
            foreach (Declaration decl in method.Arguments)
                DeclareArgument(decl);
            method.Arguments.Reverse();
            foreach (SyntaxNode sm in method.Body.Body)
                CompileLine(sm);
            Assembler.Emit(new ret());
            Symbols.EndScope();
        }
		public void CreateExternalMethod(ExternalMethod method)
        {
            
            Assembler.CreateExternalSymbol(GetMethodName(method));
			Console.WriteLine(GetMethodName(method));
        }
        public void CreateMethod(Method method)
        {
            Symbols.BeginScope();
			this.ReturnType = method.Type;
            Assembler.CreateLabel(GetMethodName(method));
            method.Arguments.Reverse();
            foreach (Declaration decl in method.Arguments)
                DeclareArgument(decl);
            method.Arguments.Reverse();
            foreach (SyntaxNode sm in method.Body.Body)
                CompileLine(sm);
            Assembler.Emit(new ret());
            Symbols.EndScope();

        }
    }

}